package game.roles.bullets;

import game.frame.MainFrame;
import game.roles.Role;
import game.roles.bullets.EnemyBullet;
import game.roles.enemys.EnemyRole;
import game.roles.gamer.Gamer;
import game.roles.visual.Blast;
import game.utils.ImageChange;

import java.awt.*;
import java.util.Random;

/**
 * @author liuyulai
 * Created with IntelliJ IDEA.
 * Date: 21.5.8
 * Time: 16:19
 * Description: 鸵鸟放屁效果
 */
public class RoundBoom extends Role {

    public static Image[] flowerImage;

    private ImageChange rm = new ImageChange(3);

    private int direction;

    public RoundBoom(Gamer gamer, int direction) {
        super(gamer.x, gamer.y, 0, 0);
        this.width = new Random().nextInt(60) + 10;
        this.height = this.width;
        this.direction = direction;
    }

    @Override
    public void rolesMove() {
        this.img = rm.change(flowerImage);

        if (this.direction == 0) {
            this.y += Math.random() * 12 + 8;
            this.x += Math.random() * 12 + 8;
        } else if (this.direction == 1) {
            this.x -= Math.random() * 12 + 8;
            this.y -= Math.random() * 12 + 8;
        } else if (this.direction == 2) {
            this.x += Math.random() * 12 + 8;
            this.y -= Math.random() * 12 + 8;
        } else if (this.direction == 3) {
            this.x -= Math.random() * 12 + 8;
            this.y += Math.random() * 12 + 8;
        }

        for (int i = 0; i < MainFrame.roleList.size(); i++) {
            Role r = MainFrame.roleList.get(i);
            if (r instanceof EnemyRole && this.rec.intersects(r.rec)) {
                EnemyRole s1 = (EnemyRole) r;
                s1.byHit(20);
                MainFrame.roleList.remove(this);
                MainFrame.roleList.add(new Blast(this.x, this.y));
                return;
            } else if (r instanceof EnemyBullet && this.rec.intersects(r.rec)) {
                MainFrame.roleList.remove(r);
                MainFrame.roleList.add(new Blast(this.x, this.y));
                i--;
            }
        }

    }
}
